// pages/detail-purchase/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    confirmorder:[],
    hiddenModal2:true,
    number:0,
    information:'选填,建议先和商家沟通后在填写',
    quantity:1,
    hejishu:null,
    kexiya:0,
    kewu:'',
    id:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    try {
      var value = wx.getStorageSync('key'||'')
      if (value) {
        this.setData({kewu:value[this.data.id]})
        console.log(this.data.kewu);
      }else{
       
      }
    } catch (e) {
      
      // Do something when catch error
    }
    let key=JSON.parse(decodeURIComponent(options.item))
    this.setData({confirmorder:key})
    this.setData({kexiya:this.data.confirmorder.Price})
    this.setData({hejishu:this.data.confirmorder.Price})
  },
  model2confirm:function(){
    let key=this.data.information
    this.setData({hiddenModal2:true})
    this.setData({information:key})
  },
  model2cancel:function(){
    this.setData({hiddenModal2:true})
    this.setData({information:'选填,建议先和商家沟通后在填写'})
  },
  getDataBindTap:function(e){
    let numberr=e.detail.cursor
    let valuee=e.detail.value
    this.data.information=valuee
    this.setData({number:numberr})
  },
  dianjil:function(){
    this.setData({hiddenModal2:false})
    this.setData({information:''})
  },
  jianfa:function(){
    if(this.data.quantity>1){
      let zhikey=this.data.quantity
      zhikey--
      this.setData({quantity:zhikey--})
      let keyi=this.data.hejishu
      let oo=this.data.kexiya
      let zongyi=oo-keyi
      this.setData({kexiya:zongyi.toFixed(2)})
      }else{
      wx.showToast({
		  	title: '数量不能再少了',
		  	duration: 2000
		})
    }
  },
  jiafa:function(){
    let zhik=1
    zhik+=this.data.quantity
    this.setData({quantity:zhik})

    let danjia= this.data.hejishu
    let shuliang=this.data.quantity
    let heji=danjia*shuliang
    
    this.setData({kexiya:heji.toFixed(2)})
  },
  xiaosi:function(){
     if(this.data.kewu==""){
      wx.navigateTo({
        url:'../detail-receiving/index'
      })
     }else{
      wx.navigateTo({
        url:'../detail-address/index'
      })
     }
  },
  xiadan:function(){
    if(this.data.kewu!=""){
      wx.showToast({
        title: '购买成功',
        icon: 'success',
        duration: 2000
      },)
    setTimeout(()=>{
      wx.reLaunch({
        url: '../home-page/index'
      })
    },1000)

    }
  },
  onShow() {
    try {
      var value = wx.getStorageSync('key'||'')
      if (value) {
        this.setData({kewu:value[this.data.id]})
      }else{ 
      }
    } catch (e) {
      
      // Do something when catch error
    }
  },
})
